package com.example.wxy.bbtapp.Common;

import android.app.ActivityManager;
import android.content.Context;

import java.util.ArrayList;

/**
 * Created by yons on 2017/9/15.
 */

public class ServiceHelper {
        /**
         * 判断服务是否开启
         *
         * @return
         */
        public static boolean isServiceRunning(Context context, String ServiceName) {
            if (("").equals(ServiceName) || ServiceName == null)
                return false;
            ActivityManager myManager = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
            ArrayList<ActivityManager.RunningServiceInfo> runningService = (ArrayList<ActivityManager.RunningServiceInfo>) myManager
                    .getRunningServices(1000);
            for (int i = 0; i < runningService.size(); i++) {
                if (runningService.get(i).service.getClassName().toString()
                        .indexOf("BBTService") > -1) {
                    return true;
                }
            }
            return false;
        }
}
